let points = [
    {x:0, y: 1},
    {x:1, y: 1}
];

d = points[1].x - points[0].x

console.log(d)

points.dist = function(){
    let p1 = this[0]
    let p2 = this[1]
    let a = p2.x-p1.x
    let b = p2.y-p1.y
    return Math.sqrt(a*a + b*b)
}

distance = points.dist()

console.log(points)

class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }

    distance() {
        return Math.sqrt(this.x*this.x + this.y*this.y);
    }
}

let p = new Point(1, 1);
console.log(p.distance());